home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / scm / slib / rscheme.init < prev    next >
Text File  |  1999-04-19  |  9KB  |  283 lines

  1. ;;;"RScheme.init" Initialization for SLIB for RScheme    -*-scheme-*-
  2. ;;;;        From http://www.rscheme.org/rs/pg1/RScheme.scm
  3. ;;; Author: Aubrey Jaffer
  4. ;;;
  5. ;;; This code is in the public domain.
  6. ;;;
  7. ;;;  adapted for RScheme by Donovan Kolbly -- (v1 1997-09-14)
  8. ;;;
  9. ;Permission to copy this software, to redistribute it, and to use it
  10. ;for any purpose is granted, subject to the following restrictions and
  11. ;understandings.
  12. ;
  13. ;1.  Any copy made of this software must include this copyright notice
  14. ;in full.
  15. ;
  16. ;2.  I have made no warrantee or representation that the operation of
  17. ;this software will be error-free, and I am under no obligation to
  18. ;provide any services, by way of maintenance, update, or otherwise.
  19. ;
  20. ;3.  In conjunction with products arising from the use of this
  21. ;material, there shall be no use of my name in any advertising,
  22. ;promotional, or sales literature without prior written consent in
  23. ;each case.
  24.  
  25. ;;; (software-type) should be set to the generic operating system type.
  26. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  27.  
  28. (define (software-type) 'UNIX)
  29.  
  30. ;;; (scheme-implementation-type) should return the name of the scheme
  31. ;;; implementation loading this file.
  32.  
  33. (define (scheme-implementation-type) 'RScheme)
  34.  
  35. ;;; (scheme-implementation-home-page) should return a (string) URL
  36. ;;; (Uniform Resource Locator) for this scheme implementation's home
  37. ;;; page; or false if there isn't one.
  38.  
  39. (define (scheme-implementation-home-page) "http://www.rscheme.org/")
  40.  
  41. ;;; (scheme-implementation-version) should return a string describing
  42. ;;; the version the scheme implementation loading this file.
  43.  
  44. (define (scheme-implementation-version) "0.7.1")
  45.  
  46. ;;; (implementation-vicinity) should be defined to be the pathname of
  47. ;;; the directory where any auxillary files to your Scheme
  48. ;;; implementation reside.
  49.  
  50. (define (implementation-vicinity)
  51.   (case (software-type)
  52.     ((UNIX)     "/usr/local/lib/rs/0.7.1/")
  53.     ((VMS)    "scheme$src:")
  54.     ((MS-DOS)    "C:\\scheme\\")))
  55.  
  56. ;;; (library-vicinity) should be defined to be the pathname of the
  57. ;;; directory where files of Scheme library functions reside.
  58.  
  59. (define library-vicinity
  60.   (let ((library-path
  61.      (or
  62.       ;; Use this getenv if your implementation supports it.
  63.       (getenv "SCHEME_LIBRARY_PATH")
  64.       ;; Use this path if your scheme does not support GETENV
  65.       ;; or if SCHEME_LIBRARY_PATH is not set.
  66.       (case (software-type)
  67.         ((UNIX) "/usr/lib/slib/")
  68.         ((VMS) "lib$scheme:")
  69.         ((MS-DOS) "C:\\SLIB\\")
  70.         (else "")))))
  71.     (lambda () library-path)))
  72.  
  73. ;;; *FEATURES* should be set to a list of symbols describing features
  74. ;;; of this implementation.  Suggestions for features are:
  75.  
  76. (define *features*
  77.       '(
  78.     source                ;can load scheme source files
  79.                     ;(slib:load-source "filename")
  80. ;    compiled            ;can load compiled files
  81.                     ;(slib:load-compiled "filename")
  82.     rev4-report            ;conforms to
  83. ;    rev3-report            ;conforms to
  84. ;    ieee-p1178            ;conforms to
  85. ;    sicp                ;runs code from Structure and
  86.                     ;Interpretation of Computer
  87.                     ;Programs by Abelson and Sussman.
  88.     rev4-optional-procedures    ;LIST-TAIL, STRING->LIST,
  89.                     ;LIST->STRING, STRING-COPY,
  90.                     ;STRING-FILL!, LIST->VECTOR,
  91.                     ;VECTOR->LIST, and VECTOR-FILL!
  92. ;    rev2-procedures            ;SUBSTRING-MOVE-LEFT!,
  93.                     ;SUBSTRING-MOVE-RIGHT!,
  94.                     ;SUBSTRING-FILL!,
  95.                     ;STRING-NULL?, APPEND!, 1+,
  96.                     ;-1+, <?, <=?, =?, >?, >=?
  97.     multiarg/and-            ;/ and - can take more than 2 args.
  98.     multiarg-apply            ;APPLY can take more than 2 args.
  99. ;    rationalize
  100.     delay                ;has DELAY and FORCE
  101.     with-file            ;has WITH-INPUT-FROM-FILE and
  102.                     ;WITH-OUTPUT-FROM-FILE
  103.     string-port            ;has CALL-WITH-INPUT-STRING and
  104.                     ;CALL-WITH-OUTPUT-STRING
  105. ;    transcript            ;TRANSCRIPT-ON and TRANSCRIPT-OFF
  106.     char-ready?
  107. ;    macro                ;has R4RS high level macros
  108. ;    defmacro            ;has Common Lisp DEFMACRO
  109. ;    eval                ;SLIB:EVAL is single argument eval
  110. ;    record                ;has user defined data structures
  111. ;    values                ;proposed multiple values
  112. ;    dynamic-wind            ;proposed dynamic-wind
  113. ;    ieee-floating-point        ;conforms to
  114.     full-continuation        ;can return multiple times
  115. ;    object-hash            ;has OBJECT-HASH
  116.  
  117. ;    sort
  118. ;    queue                ;queues
  119. ;    pretty-print
  120. ;    object->string
  121. ;    format
  122. ;    trace                ;has macros: TRACE and UNTRACE
  123. ;    compiler            ;has (COMPILER)
  124. ;    ed                ;(ED) is editor
  125. ;    system                ;posix (system <string>)
  126.     getenv                ;posix (getenv <string>)
  127. ;    program-arguments        ;returns list of strings (argv)
  128. ;    Xwindows            ;X support
  129. ;    curses                ;screen management package
  130. ;    termcap                ;terminal description package
  131. ;    terminfo            ;sysV terminal description
  132. ;    current-time            ;returns time in seconds since 1/1/1970
  133.     ))
  134.  
  135. ;;; (OUTPUT-PORT-WIDTH <port>)
  136. (define (output-port-width . arg) 79)
  137.  
  138. ;;; (OUTPUT-PORT-HEIGHT <port>)
  139. (define (output-port-height . arg) 24)
  140.  
  141. ;;; (CURRENT-ERROR-PORT)
  142. ;(define current-error-port
  143. ;  (let ((port (current-output-port)))
  144. ;    (lambda () port)))
  145.  
  146. ;;; (TMPNAM) makes a temporary file name.
  147. (define tmpnam (let ((cntr 100))
  148.          (lambda () (set! cntr (+ 1 cntr))
  149.              (string-append "slib_" (number->string cntr)))))
  150.  
  151. ;;; (FILE-EXISTS? <string>)
  152. (define (file-exists? f) (os-file-exists? f))
  153.  
  154. ;;; (DELETE-FILE <string>)
  155. (define (delete-file f) #f)
  156.  
  157. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  158. ;;; use this definition if your system doesn't have such a procedure.
  159. (define (force-output . arg)
  160.   (flush-output-port (if (null? arg)
  161.              (current-output-port)
  162.              (car arg))))
  163.  
  164. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  165. ;;; port versions of CALL-WITH-*PUT-FILE.
  166.  
  167. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  168. ;;; be returned by CHAR->INTEGER.
  169. (define char-code-limit 65536)
  170.  
  171. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  172. (define most-positive-fixnum #x1FFFFFFF)
  173.  
  174. ;;; Return argument
  175. ;;(define (identity x) x)
  176.  
  177. ;;; If your implementation provides eval SLIB:EVAL is single argument
  178. ;;; eval using the top-level (user) environment.
  179. (define slib:eval eval)
  180.  
  181. ;;; If your implementation provides R4RS macros:
  182. ;(define macro:eval slib:eval)
  183. ;(define macro:load load)
  184.  
  185. (define *defmacros*
  186.   (list (cons 'defmacro
  187.           (lambda (name parms . body)
  188.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  189.                       *defmacros*))))))
  190. (define (defmacro? m) (and (assq m *defmacros*) #t))
  191.  
  192. (define (macroexpand-1 e)
  193.   (if (pair? e) (let ((a (car e)))
  194.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  195.                      (if a (apply (cdr a) (cdr e)) e))
  196.             (else e)))
  197.       e))
  198.  
  199. (define (macroexpand e)
  200.   (if (pair? e) (let ((a (car e)))
  201.           (cond ((symbol? a)
  202.              (set! a (assq a *defmacros*))
  203.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  204.             (else e)))
  205.       e))
  206.  
  207. (define gentemp
  208.   (let ((*gensym-counter* -1))
  209.     (lambda ()
  210.       (set! *gensym-counter* (+ *gensym-counter* 1))
  211.       (string->symbol
  212.        (string-append "slib:G" (number->string *gensym-counter*))))))
  213.  
  214. (define base:eval slib:eval)
  215. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  216. (define (defmacro:expand* x)
  217.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  218.  
  219. (define (defmacro:load <pathname>)
  220.   (slib:eval-load <pathname> defmacro:eval))
  221.  
  222. (define (slib:eval-load <pathname> evl)
  223.   (if (not (file-exists? <pathname>))
  224.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  225.   (call-with-input-file <pathname>
  226.     (lambda (port)
  227.       (let ((old-load-pathname *load-pathname*))
  228.     (set! *load-pathname* <pathname>)
  229.     (do ((o (read port) (read port)))
  230.         ((eof-object? o))
  231.       (evl o))
  232.     (set! *load-pathname* old-load-pathname)))))
  233.  
  234. ;;; define an error procedure for the library
  235. (define (slib:error msg . args)
  236.   (error "~a ~j" msg args))
  237.  
  238. ;;; define these as appropriate for your system.
  239. (define slib:tab (integer->char 9))
  240. (define slib:form-feed (integer->char 12))
  241.  
  242. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  243. ;(define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l))
  244. (define t #t)
  245. (define nil #f)
  246.  
  247. ;;; Define these if your implementation's syntax can support it and if
  248. ;;; they are not already defined.
  249.  
  250. ;(define (1+ n) (+ n 1))
  251. ;(define (-1+ n) (+ n -1))
  252. ;(define 1- -1+)
  253.  
  254. (define in-vicinity string-append)
  255.  
  256. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  257. ;;; return if exitting not supported.
  258. (define slib:exit (lambda args (process-exit 0)))
  259.  
  260. ;;; Here for backward compatability
  261. (define scheme-file-suffix
  262.   (let ((suffix (case (software-type)
  263.           ((NOSVE) "_scm")
  264.           (else ".scm"))))
  265.     (lambda () suffix)))
  266.  
  267. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  268. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  269.  
  270. (define (slib:load-source f) (load (string-append f ".scm")))
  271.  
  272. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  273. ;;; by compiling "foo.scm" if this implementation can compile files.
  274. ;;; See feature 'COMPILED.
  275.  
  276. (define slib:load-compiled load)
  277.  
  278. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  279.  
  280. (define slib:load slib:load-source)
  281.  
  282. (slib:load (in-vicinity (library-vicinity) "require"))
  283.